<?php
error_reporting(E_ALL);
if(session_start()) ; //echo "session started";
include('./paginator/ajaxpaginator.class.php');
require ("dbconf.php");
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);
// instantiate mysqli connection
// CHANGE THESE SETTINGS
 
$recPerPage = 50;//number of records per page

$query = "SELECT * FROM files ";

// if there is a a search query
$searchQuery = !empty($_GET['search'])?$searchQuery = $_GET['search']:''; 
$pageId= empty($_GET['page'])? 1:$mysqli->real_escape_string($_GET['page']); 


$paginator = new AjaxPaginator($pageId,$recPerPage,$query,$mysqli);

$paginator->searchQuery = $searchQuery;

// database field to search in
//$pagination->fields = 'name';
// or try array
// passing an array makes the search text to search in the name or the id
$paginator->fields = array('directory_id','name','extension','stamp_creation','byte_size','firstbytes');

// Get the paginated rows
try{
	$rows = $paginator->paginate();
}catch (Exception $e){
	echo $e->getMessage();
	$rows=array();
}

?>
<script type="text/javascript">
	$('.paginator a').click(function () {
		$('#listing_container').Paginate(this.id);
		return false;	
	});
</script>

    <table border="0" cellpadding="2" cellspacing="0" class="listing">
	<tr>
		<th nowrap="nowrap" width="40"> ID</th>
		<th nowrap="nowrap" width="450" align='left'>Name</th>
	</tr>
<?php

 

if ($rows){
	foreach($rows as $row){
		echo "<tr>";
			echo "<td nowrap='nowrap' align='center'>{$row['directory_id']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['name']}</td>";
			echo "<td nowrap='nowrap' align='center'>{$row['extension']}</td>";			
			echo "<td nowrap='nowrap' align='center'>{$row['stamp_creation']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['byte_size']}</td>";
			echo "<td nowrap='nowrap' align='left'>{$row['firstbytes']}</td>";
		echo "</tr>";
	}
}
echo "</table><br />";

echo "<div class='paginator'> " . $paginator->getLinks () ;

echo "<br /><p>Page " . $paginator->pageId . "  of " . $paginator->totalPages."</p>". "</div>";
